param (
    [string]$User="",
    [string]$User_pwd="",
    [string]$DatabaseName=""
)

$DATA_BACKUP_AGENT_HOME = (Get-ChildItem env:DATA_BACKUP_AGENT_HOME).Value
$Location = $DATA_BACKUP_AGENT_HOME + "\DataBackup\ProtectClient\Plugins\GeneralDBPlugin\bin\applications\exchange\ps1_scripts"
Set-Location -Path $Location
[string]$common_file_path = (Get-Location).Path + "\Common.ps1"
[string]$pssession_name = "SuspendPassiveCopyReplication"

# 引用Common.ps1
. $common_file_path

if (!(NewConnection $User $User_Pwd $pssession_name)) {
    return $False
}

try {
    $DB_details = Invoke-Command -Session $Session -ScriptBlock {Get-MailboxDatabaseCopyStatus -Identity $using:DatabaseName}
    # 禁用恢复数据库副本功能
    foreach ($db in $DB_details) {
        $db_name = $db.Name
        # 禁用自动激活,避免恢复时主备交换
        Invoke-Command -Session $Session -ScriptBlock {Suspend-MailboxDatabaseCopy -Identity $using:db_name -ActivationOnly -Confirm:$False}
        if ([String]$db.Status -eq "Healthy") {
            Invoke-Command -Session $Session -ScriptBlock {Suspend-MailboxDatabaseCopy -Identity $using:db_name -Confirm:$False}
        }
    }
} catch {
    ClosePSSession $pssession_name
    return $False
}
ClosePSSession $pssession_name
return $True
